# Maintainer: Tim Meusel <tim@bastelfreak.de>

_gemname='faraday-rack'
pkgname="ruby-${_gemname}"
pkgver=1.0.0
pkgrel=1
pkgdesc='About Faraday adapter for Rack'
arch=('any')
url="https://github.com/lostisland/${_gemname}"
license=('MIT')
depends=('ruby' 'ruby-rack')
makedepends=('ruby-rspec')
checkdepends=('ruby-faraday' 'ruby-webmock' 'ruby-multipart-parser' 'ruby-rack-test')
#checkdepends=('ruby-rspec' 'ruby-rack' 'ruby-webmock' 'ruby-httpclient' 'ruby-rspec-expectations' 'ruby-multipart-parser' 'ruby-rack-test')
options=('!emptydirs')
source=("${url}/archive/v${pkgver}/${_gemname}-v${pkgver}.tar.gz")
sha512sums=('c2abe89a54c41dfa336976ec0f8c86f3a1912b5a950f139f0146a27273560fa74c97c5c35d05f80ce2349de96461b7e398c79cdc3471a8fe782406df03e184ec')

prepare() {
  cd "${srcdir}/${_gemname}-${pkgver}"

  # drop broken/cirular dependencies
  sed --in-place '/add_development_dependency/d' "${_gemname}.gemspec"
}

build() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  gem build "${_gemname}.gemspec"
}

check() {
  cd "${srcdir}/${_gemname}-${pkgver}"
  # tests don't yet pass because some deps are missing in the repos
  rspec
}

package() {
cd "${srcdir}/${_gemname}-${pkgver}"
  local _gemdir="$(gem env gemdir)"
  gem install --verbose --ignore-dependencies --no-user-install --install-dir "${pkgdir}/${_gemdir}" --bindir "${pkgdir}/usr/bin" "${_gemname}-${pkgver}.gem"

  install -Dm 644 LICENSE.md -t "${pkgdir}/usr/share/licenses/${pkgname}/"

  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"

  rm -rf "${pkgdir}/${_gemdir}/cache"
}
